package com.hunan.api.catv.action.like;

import com.hunan.api.catv.action.BaseAction;
import com.hunan.api.catv.annotation.MemberAuth;
import com.hunan.api.catv.common.Api;
import com.hunan.api.catv.entity.Result;
import com.hunan.api.catv.service.biz.like.MemberLikeBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 点赞
 */
@RestController
@RequestMapping(Api.like)
public class LikeAction extends BaseAction {

    @Autowired
    MemberLikeBiz memberLikeBiz;

    /**
     * 新增点赞
     */
    @MemberAuth
    @PostMapping("/member")
    public Result add(HttpServletRequest request, Integer collectType, Integer type, Integer itemId) {
        if (ObjectUtils.isEmpty(collectType)) {
            return buildRequire("collectType require");
        }
        if (ObjectUtils.isEmpty(type)) {
            return buildRequire("type require");
        }
        if (ObjectUtils.isEmpty(itemId)) {
            return buildRequire("itemId require");
        }
        return buildResult(memberLikeBiz.like(collectType, type, itemId, getMemberId(request)));
        //return buildResult(memberLikeBiz.like(collectType,type,itemId,555));
    }

    /**
     * 查询用户是否点赞
     */
    @MemberAuth
    @GetMapping("/itemLike")
    public Result itemLike(HttpServletRequest request, Integer type, Integer itemId) {
        if (ObjectUtils.isEmpty(type)) {
            return buildRequire("type require");
        }
        if (ObjectUtils.isEmpty(itemId)) {
            return buildRequire("itemId require");
        }
        return buildResult(memberLikeBiz.itemLike(type, itemId, getMemberId(request)));
    }

    @MemberAuth
    @GetMapping("/queryAll")
    public Result queryAll(HttpServletRequest request, Integer type) {
        if (ObjectUtils.isEmpty(type)) {
            return buildRequire("type require");
        }
        return buildOK(memberLikeBiz.queryAll(type, getMemberId(request)), "");
        //return buildOK(memberLikeBiz.queryAll(type, 1), "");
    }
}
